package com.zhelun.demo.activity;

import android.app.Activity;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.zhelun.demo.MovieTop250Contract;
import com.zhelun.demo.R;
import com.zhelun.demo.SubjectsBean;
import com.zhelun.demo.TopMoviePresenter;
import com.zhelun.demo.ada.TopMovieAda;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import demo.bocweb.com.sdk.base.BasePresenter;
import demo.bocweb.com.sdk.base.activity.BaseMVPActivity;
import demo.bocweb.com.sdk.config.ARoutConfig;
import demo.bocweb.com.sdk.manager.MessageEvent;
import demo.bocweb.com.sdk.util.PhotoPickerHelper;
import demo.bocweb.com.sdk.util.ToastUtils;
import demo.bocweb.com.sdk.util.ToastyUtil;

@Route(path = ARoutConfig.mainPath)
public class MainActivity extends BaseMVPActivity<MovieTop250Contract.TopMoviePresenter, MovieTop250Contract.IMovieTop250Model> implements MovieTop250Contract.IMovieTop250View {

    @BindView(R.id.lv)
    ListView lv;
    @BindView(R.id.btn_book)
    Button btnBook;
    @BindView(R.id.single)
    Button single;
    @BindView(R.id.single_no_crop)
    Button singleNoCrop;
    @BindView(R.id.more)
    Button more;
    @BindView(R.id.more_no_camera)
    Button moreNoCamera;
    @BindView(R.id.error)
    Button error;
    @BindView(R.id.info)
    Button info;
    @BindView(R.id.normal)
    Button normal;
    @BindView(R.id.success)
    Button success;
    @BindView(R.id.warning)
    Button warning;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.web)
    Button btnWeb;
    private TopMovieAda ada;
    private List<SubjectsBean> dataes = new ArrayList<>();
    private int page = 1;
    private Activity activity;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_main;
    }

    @NonNull
    @Override
    public BasePresenter initPresenter() {
        return TopMoviePresenter.newInstance();
    }

    @Override
    protected void initData() {
        super.initData();
        this.activity = this;
        btnBook.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance().build("/book/main_activity").navigation();


            }
        });
        ada = new TopMovieAda(dataes, this);
        lv.setAdapter(ada);
        lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ARouter.getInstance().build("/movie/info_activity")
                        .withString("url", dataes.get(i).getAlt())
                        .navigation();

            }
        });
        mPresenter.getTopMovieList(page, 20);
    }


    @Override
    public void updateTopMovieList(List<SubjectsBean> list) {
        if (page == 1) {
            dataes.clear();
        }
        dataes.addAll(list);
        ada.notifyDataSetChanged();
    }

    @Override
    public void onMainEvent(MessageEvent messageEvent) {
        super.onMainEvent(messageEvent);
        ToastUtils.showToast(messageEvent.getMessage());
    }


    @OnClick({R.id.single, R.id.single_no_crop, R.id.more, R.id.more_no_camera, R.id.error,R.id.web,
            R.id.info, R.id.normal, R.id.success, R.id.warning, R.id.btn_login, R.id.btn_choose_address, R.id.btn_address_list})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.single:
                PhotoPickerHelper.selectSinglePhoto(activity, 1000, true);
                break;
            case R.id.single_no_crop:
                PhotoPickerHelper.selectSinglePhoto(activity, 1000, false);
                break;
            case R.id.more:
                PhotoPickerHelper.selectMultiPhoto(activity, 1000, 9);
                break;
            case R.id.more_no_camera:
                PhotoPickerHelper.selectMultiPhoto(activity, 1000, 9, false);
                break;
            case R.id.error:
                ToastyUtil.showError("error");
                break;
            case R.id.info:
                ToastyUtil.showInfo("info");
                break;
            case R.id.normal:
                ToastyUtil.showNormal("normal");
                break;
            case R.id.success:
                ToastyUtil.showSuccess("success");
                break;
            case R.id.warning:
                ToastyUtil.showWarning("warning");
                break;
            case R.id.btn_login:
                ARouter.getInstance().build(ARoutConfig.loginPath).navigation();
                break;
            case R.id.btn_choose_address:
                ARouter.getInstance().build(ARoutConfig.addAddressPath).navigation();
                break;
            case R.id.btn_address_list:
                ARouter.getInstance().build(ARoutConfig.addressListPath)
                        .navigation();
                break;
            case R.id.web:
                ARouter.getInstance().build(ARoutConfig.demoWebViewPath)
                        .greenChannel()
                        .navigation();
                break;

        }
    }

}
